﻿<?xml version="1.0" encoding="utf-8"?><Articles><Article><ArticlesID>563</ArticlesID><Title>Lập tr&amp;#236;nh đa ng&amp;#244;n ngữ với .NET</Title><Body>&amp;lt;p&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt;C&amp;#243; r&amp;amp;acirc;́t nhi&amp;amp;ecirc;̀u c&amp;#225;ch đ&amp;amp;ecirc;̉ l&amp;#224;m ứng dụng website đ&amp;#227; ng&amp;amp;ocirc;n ngữ, từ đơn giản đ&amp;amp;ecirc;́n phức tạp. Dưới đ&amp;amp;acirc;y l&amp;#224; giao di&amp;amp;ecirc;̣n của ứng dụng:&amp;lt;br /&amp;gt;
&amp;amp;nbsp;&amp;lt;br /&amp;gt;
&amp;lt;/span&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img height=&amp;quot;272&amp;quot; width=&amp;quot;400&amp;quot; alt=&amp;quot;MultiLanguage Website&amp;quot; src=&amp;quot;http://dev.meotom.net/Uploads/admin/2009/10/29/multilanguages1.jpg&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img height=&amp;quot;267&amp;quot; width=&amp;quot;400&amp;quot; alt=&amp;quot;MultiLanguages Website&amp;quot; src=&amp;quot;http://dev.meotom.net/Uploads/admin/2009/10/29/multilanguages2.jpg&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;amp;nbsp;Trong Dot Net FrameWork, c&amp;#243; 2 đ&amp;amp;ocirc;́i tượng gi&amp;#250;p ta l&amp;#224;m vi&amp;amp;ecirc;̣c n&amp;#224;y:&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; - ResourceManager (System.Resources.ResourceManager)&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; - CultureInfo (System.Globalization.CultureInfo)&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;&amp;amp;nbsp;Ứng dụng n&amp;#224;y sẽ chỉ l&amp;#224;m 2 Ng&amp;amp;ocirc;n ngữ, đ&amp;#243; l&amp;#224; ti&amp;amp;ecirc;́ng vi&amp;amp;ecirc;̣t v&amp;#224; ti&amp;amp;ecirc;́ng anh. V&amp;#236; v&amp;amp;acirc;̣y, đ&amp;amp;acirc;̀u ti&amp;amp;ecirc;n ch&amp;#250;ng ta sẽ tạo ra 2 lớp c&amp;#243; đu&amp;amp;ocirc;i &amp;lt;strong&amp;gt;.resx&amp;lt;/strong&amp;gt;. Đ&amp;#243; ch&amp;#237;nh l&amp;#224; Resource File. M&amp;amp;ocirc;̣t lớp ch&amp;#250;ng ta sẽ đặt t&amp;amp;ecirc;n l&amp;#224; &amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;SiteMap.resx&amp;lt;/strong&amp;gt;&amp;lt;/font&amp;gt; v&amp;#224; lớp kia c&amp;#243; t&amp;amp;ecirc;n l&amp;#224; &amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;SiteMap.en-US.resx&amp;lt;/strong&amp;gt;&amp;lt;/font&amp;gt;. C&amp;#225;c bạn h&amp;#227;y đ&amp;amp;ecirc;̉ &amp;#253; t&amp;amp;ecirc;n của 2 file tr&amp;amp;ecirc;n nh&amp;#233;. Ở đ&amp;amp;acirc;y, File SiteMap.resx sẽ l&amp;#224; file ngu&amp;amp;ocirc;̀n mặc định.&amp;amp;nbsp; C&amp;#225;c gi&amp;#225; trị nh&amp;amp;acirc;̣p v&amp;#224;o sẽ như sau:&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img height=&amp;quot;231&amp;quot; width=&amp;quot;400&amp;quot; alt=&amp;quot;MultiLanguage Website&amp;quot; src=&amp;quot;http://dev.meotom.net/Uploads/admin/2009/10/29/multilanguages3.jpg&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;Bạn chỉ c&amp;amp;acirc;̀n quan t&amp;amp;acirc;m đ&amp;amp;ecirc;́n 2 c&amp;amp;ocirc;̣t: Name v&amp;#224; Value. C&amp;#242;n dưới đ&amp;amp;acirc;y l&amp;#224; file SiteMap.en-US.resx:&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;center&amp;quot;&amp;gt;&amp;lt;img height=&amp;quot;240&amp;quot; width=&amp;quot;400&amp;quot; alt=&amp;quot;MultiLanguages Website&amp;quot; src=&amp;quot;http://dev.meotom.net/Uploads/admin/2009/10/29/multilanguages5.jpg&amp;quot; /&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;justify&amp;quot;&amp;gt;2 File c&amp;#243; c&amp;#249;ng t&amp;amp;ecirc;n, nhưng v&amp;amp;ecirc;̀ gi&amp;#225; trị th&amp;#236; 1 file mặc định sẽ l&amp;#224; ti&amp;amp;ecirc;́ng vi&amp;amp;ecirc;̣t, c&amp;#242;n file kia sẽ c&amp;#243; gi&amp;#225; trị l&amp;#224; ti&amp;amp;ecirc;́ng anh.&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;Quay trở lại với ứng dụng, sau khi tạo ra 2 lớp tr&amp;amp;ecirc;n, ch&amp;#250; &amp;#253; l&amp;#224; phải đặt ch&amp;#250;ng ở trong thư mục &amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;App_GlobalResources&amp;lt;/strong&amp;gt;&amp;lt;/font&amp;gt; nh&amp;#233;.&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt; &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;Ch&amp;#250;ng ta phải sử dụng 3 thư vi&amp;amp;ecirc;̣n sau:&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp;&amp;amp;nbsp; &amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;- System.Globalization&amp;lt;br /&amp;gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp; - System.Threading&amp;lt;br /&amp;gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; &amp;amp;nbsp; - System.Resources&amp;lt;/font&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;Trong Trang &amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;&amp;lt;strong&amp;gt;Page_Load&amp;lt;/strong&amp;gt;&amp;lt;/font&amp;gt; ta chỉ c&amp;amp;acirc;̀n vi&amp;amp;ecirc;́t l&amp;amp;ecirc;̣nh sau:&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: csharp;&amp;quot;&amp;gt;
ResourceManager rm;
    CultureInfo ci;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(&amp;amp;quot;vi-VN&amp;amp;quot;);
            rm = new ResourceManager(&amp;amp;quot;Resources.SiteMap&amp;amp;quot;, System.Reflection.Assembly.Load(&amp;amp;quot;App_GlobalResources&amp;amp;quot;));
            ci = Thread.CurrentThread.CurrentCulture;

            LoadString(ci);
        }
        else
        {
            rm = new ResourceManager(&amp;amp;quot;Resources.SiteMap&amp;amp;quot;, System.Reflection.Assembly.Load(&amp;amp;quot;App_GlobalResources&amp;amp;quot;));
            ci = Thread.CurrentThread.CurrentCulture;

            LoadString(ci);
        }
    }&amp;lt;/pre&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt;H&amp;#224;m &amp;lt;strong&amp;gt;&amp;lt;font color=&amp;quot;#0000ff&amp;quot;&amp;gt;LoadString&amp;lt;/font&amp;gt; &amp;lt;/strong&amp;gt;ở đ&amp;amp;acirc;y c&amp;#243; mục đ&amp;#237;ch đ&amp;amp;ecirc;̉ thay đ&amp;amp;ocirc;̉i c&amp;#225;c gi&amp;#225; trị của đ&amp;amp;ocirc;́i tượng:&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: csharp;&amp;quot;&amp;gt;
public void LoadString(CultureInfo ci)
{
        lblHeader1.Text = rm.GetString(&amp;amp;quot;Header1&amp;amp;quot;, ci);
        lblHeader2.Text = rm.GetString(&amp;amp;quot;Header2&amp;amp;quot;, ci);
        lblLang.Text = rm.GetString(&amp;amp;quot;Lang&amp;amp;quot;,ci);
        lnkHoText = rm.GetString(&amp;amp;quot;Home&amp;amp;quot;, ci);
        lnkAbout.Text = rm.GetString(&amp;amp;quot;About&amp;amp;quot;, ci);
        lnkLink.Text = rm.GetString(&amp;amp;quot;Link&amp;amp;quot;, ci);
        HyperLink1.Text = rm.GetString(&amp;amp;quot;Home&amp;amp;quot;, ci); ;
        HyperLink2.Text = rm.GetString(&amp;amp;quot;About&amp;amp;quot;, ci);
        HyperLink3.Text = rm.GetString(&amp;amp;quot;Link&amp;amp;quot;, ci);
        Login1.LoginButtonText = rm.GetString(&amp;amp;quot;LoginButtonText&amp;amp;quot;,ci);
        Login1.TitleText = rm.GetString(&amp;amp;quot;LoginTitle&amp;amp;quot;,ci);
        Login1.UserNameLabelText = rm.GetString(&amp;amp;quot;LoginUser&amp;amp;quot;,ci);
        Login1.PasswordLabelText = rm.GetString(&amp;amp;quot;LoginPass&amp;amp;quot;,ci);
        Login1.RememberMeText = rm.GetString(&amp;amp;quot;LoginRemember&amp;amp;quot;,ci);
}&amp;lt;/pre&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt;Ứng dụng đ&amp;#227; cơ bản ho&amp;#224;n th&amp;#224;nh. Chỉ c&amp;#242;n vi&amp;amp;ecirc;́t sự ki&amp;amp;ecirc;̣n cho c&amp;#225;c button đ&amp;amp;ecirc;̉ thay đ&amp;amp;ocirc;̉i ng&amp;amp;ocirc;n ngữ l&amp;#224; xong:&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;pre title=&amp;quot;code&amp;quot; class=&amp;quot;brush: csharp;&amp;quot;&amp;gt;
protected void ibtEnglish_Click(object sender, ImageClickEventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(&amp;amp;quot;en-US&amp;amp;quot;);
        LoadString(Thread.CurrentThread.CurrentCulture);
    }
    protected void ibtVietNamese_Click(object sender, ImageClickEventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo(&amp;amp;quot;vi-VN&amp;amp;quot;);
        LoadString(Thread.CurrentThread.CurrentCulture);
    }&amp;lt;/pre&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;lt;span id=&amp;quot;tdStoryBody&amp;quot; class=&amp;quot;detail&amp;quot;&amp;gt;Tr&amp;amp;ecirc;n đ&amp;amp;acirc;y chỉ l&amp;#224; ứng dụng r&amp;amp;acirc;́t cơ bản v&amp;#224; đơn giản với mục đ&amp;#237;ch đ&amp;amp;ecirc;̉ giới thi&amp;amp;ecirc;̣u l&amp;#224; ch&amp;#237;nh. Hy vọng c&amp;#225;c bạn sẽ nghi&amp;amp;ecirc;n cứu chuy&amp;amp;ecirc;n s&amp;amp;acirc;u hơn đ&amp;amp;ecirc;̉ c&amp;#243; th&amp;amp;ecirc;̉ &amp;#225;p dụng v&amp;#224;o thực t&amp;amp;ecirc;́. &amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p align=&amp;quot;left&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;detail&amp;quot;&amp;gt;ST&amp;lt;/span&amp;gt;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;&amp;amp;nbsp;&amp;lt;/p&amp;gt;</Body><CommentEnabled>True</CommentEnabled><ViewCount>0</ViewCount><ReleaseDate>10/29/2009 9:20:22 AM</ReleaseDate><TotalComment>0</TotalComment><IsMedia>False</IsMedia><IsPicture>False</IsPicture><IsVote>True</IsVote><ArticlePassword /><PostVisible>0</PostVisible><ArticlePath>/2009/10/29/Lap-trinh-da-ngon-ngu-voi--NET-233</ArticlePath><Approved>True</Approved><ImagePath /><CategoryId>26</CategoryId><ArrayCatID>26|25</ArrayCatID></Article></Articles>